<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Minim : : Oscil</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body> 
<center>
<table class="mainTable">
  <tr>
    <td class="header">
    	<span class="indexheader">Minim</span><br/>
    	<span class="indexnavigation">
    		<a href="index.html">core</a> | 
    		<a href="index_ugens.html">ugens</a> | 
    		<a href="index_analysis.html">analysis</a>
    	</span>
    </td>
    <td class="border-left">&nbsp;</td>
  </tr>
  
  <tr>
    <td class="classNavigation">
    	<p class="mainTextName">Oscil</p>
    	
       <p class="linkListHeader">Fields</p>
       <p class="linkList">
           
    <a href="oscil_field_amplitude.html" title="Patch to this to control the amplitude of the oscillator with another
 UGen.">amplitude</a><br/>
    
    <a href="oscil_field_frequency.html" title="Patch to this to control the frequency of the oscillator with another
 UGen.">frequency</a><br/>
    
    <a href="oscil_field_offset.html" title="Patch to this to control the DC offset of the Oscil with another UGen. 
 This is useful when using an Oscil as a modulator.">offset</a><br/>
    
    <a href="oscil_field_phase.html" title="Patch to this to control the phase of the oscillator with another UGen.">phase</a><br/>
    
	   </p>
   
    	
       <p class="linkListHeader">Methods</p>
       <p class="linkList">
           
    <a href="oscil_method_channelcount.html" title="Returns the number of channels this UGen has been configured to generate.">channelCount ( )</a><br/>
    
    <a href="oscil_method_getlastvalues.html" title="Return the last values generated by this UGen. This will most often be
 used by sub-classes when pulling data from their inputs.">getLastValues ( )</a><br/>
    
    <a href="oscil_method_getwaveform.html" title="Returns the Waveform currently being used by this Oscil.">getWaveform ( )</a><br/>
    
    <a href="oscil_method_patch.html" title="Send the output of this UGen to another UGen, UGenInput, or AudioOutput.">patch ( )</a><br/>
    
    <a href="oscil_method_printinputs.html" title="Prints all inputs connected to this UGen (for debugging)">printInputs ( )</a><br/>
    
    <a href="oscil_method_reset.html" title="Resets the time-step used by the Oscil to be equal to the current
 phase input value.">reset ( )</a><br/>
    
    <a href="oscil_method_samplerate.html" title="Returns the sample rate of this UGen.">sampleRate ( )</a><br/>
    
    <a href="oscil_method_setamplitude.html" title="Sets the amplitude of this Oscil.">setAmplitude ( )</a><br/>
    
    <a href="oscil_method_setchannelcount.html" title="Let this UGen know how many channels of audio you will be asking it for.">setChannelCount ( )</a><br/>
    
    <a href="oscil_method_setfrequency.html" title="Sets the frequency of this Oscil.">setFrequency ( )</a><br/>
    
    <a href="oscil_method_setphase.html" title="Set the amount that the phase will be offset by.">setPhase ( )</a><br/>
    
    <a href="oscil_method_setsamplerate.html" title="Set the sample rate for this UGen.">setSampleRate ( )</a><br/>
    
    <a href="oscil_method_setwaveform.html" title="Changes the Waveform used by this Oscil.">setWaveform ( )</a><br/>
    
    <a href="oscil_method_tick.html" title="Generates one sample frame for this UGen.">tick ( )</a><br/>
    
    <a href="oscil_method_unpatch.html" title="Unpatch this UGen from an AudioOutput or other UGen.">unpatch ( )</a><br/>
    
	   </p>
   
    </td>
    <td class="mainText border-left">
    	<p>
 An Oscil is a UGen that generates audio by oscillating over a Waveform 
 at a particular frequency. For instance, if you were to create this Oscil:
 </p>
 <pre>Oscil testTone = new Oscil( 440, 1, Waves.SINE );</pre>
 <p>
 When patched to an AudioOuput, it would generate a continuous sine wave tone 
 at 440 Hz and would sound like a test tone. 
 This frequency also happens to be the same as the pitch played 
 by the lead oboist in a orchestra when they tune up at the beginning of a concert.
 </p>
 <p>
 However, rather than give Oscil a fixed, or limited, set of sounds it 
 can generate, instead it simply oscillates over a generic Waveform object. 
 Waveform is simply an <em>interface</em> that declares a value method, which 
 is used by Oscil to determine what value it should output at any given moment 
 in time. Generally, you will use predefined Waveforms from the Waves class, 
 or generated Waveforms using the WavetableGenerator class. However, there's 
 no particular reason you couldn't define your own classes that implement 
 the Waveform interface.
 </p>
 <p>
 Another abstraction the Oscil UGen makes use of is the Frequency class. 
 This class allows you to define a frequency in terms of pitch, midi note, 
 or hertz. This is often quite useful when writing musical scores with code.
 For instance, we could use the Frequency class when creating an Oscil that 
 will sound the same as the example above:
 </p>
 <pre>Oscil testTone = new Oscil( Frequency.ofPitch("A4"), 1, Waves.SINE );</pre>
    	<p class="memberSectionHeader">Constructors</p>
    	<pre><em>Constructs an Oscil UGen, given frequency in Hz, amplitude, and a waveform</em>
Oscil(float frequencyInHertz, float amplitude, Waveform waveform)
<em>Constructs an Oscil UGen given frequency in Hz and amplitude. This
 oscillator uses a sine wave.</em>
Oscil(float frequencyInHertz, float amplitude)
<em>Constructs an Oscil UGen given a Frequency and amplitude. This oscillator
 uses a sine wave.</em>
Oscil(Frequency frequency, float amplitude)
<em>Constructs an Oscil UGen given a Frequency, amplitude, and a waveform</em>
Oscil(Frequency frequency, float amplitude, Waveform waveform)
</pre>
    	
   <p class="memberSectionHeader">Parameters</p>
   
        <span class="parameterName">frequencyInHertz</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">float: the frequency this Oscil should oscillate at</span><br/>
    
        <span class="parameterName">amplitude</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">float: the amplitude of this Oscil.</span><br/>
    
        <span class="parameterName">waveform</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">Waveform: the waveform this Oscil will oscillate over</span><br/>
    
        <span class="parameterName">frequency</span>&nbsp;&mdash;&nbsp;<span class="parameterDescription">Frequency: the frequency this Oscil should oscillate at.</span><br/>
    
   
    	<p class="memberSectionHeader">Related</p>
    	<A href="ugen_class_ugen.html">UGen</A><BR>
<A href="waveform_waveform.html">Waveform</A><BR>
<A href="waves_class_waves.html">Waves</A><BR>
<A href="wavetablegenerator_class_wavetablegenerator.html">WavetableGenerator</A><BR>
<A href="frequency_class_frequency.html">Frequency</A><BR>

    	<p class="memberSectionHeader">Example</p>
    	<pre>/**
  * This sketch demonstrates how to create synthesized sound with Minim 
  * using an AudioOutput and an Oscil. An Oscil is a UGen object, 
  * one of many different types included with Minim. By using 
  * the numbers 1 thru 5, you can change the waveform being used
  * by the Oscil to make sound. These basic waveforms are the 
  * basis of much audio synthesis. 
  * 
  * For many more examples of UGens included with Minim, 
  * have a look in the Synthesis folder of the Minim examples.
  * &lt;p>
  * For more information about Minim and additional features, 
  * visit http://code.compartmental.net/minim/
  */

import ddf.minim.*;
import ddf.minim.ugens.*;

Minim       minim;
AudioOutput out;
Oscil       wave;

void setup()
{
  size(512, 200, P3D);
  
  minim = new Minim(this);
  
  // use the getLineOut method of the Minim object to get an AudioOutput object
  out = minim.getLineOut();
  
  // create a sine wave Oscil, set to 440 Hz, at 0.5 amplitude
  wave = new Oscil( 440, 0.5f, Waves.SINE );
  // patch the Oscil to the output
  wave.patch( out );
}

void draw()
{
  background(0);
  stroke(255);
  strokeWeight(1);
  
  // draw the waveform of the output
  for(int i = 0; i &lt; out.bufferSize() - 1; i++)
  {
    line( i, 50  - out.left.get(i)*50,  i+1, 50  - out.left.get(i+1)*50 );
    line( i, 150 - out.right.get(i)*50, i+1, 150 - out.right.get(i+1)*50 );
  }

  // draw the waveform we are using in the oscillator
  stroke( 128, 0, 0 );
  strokeWeight(4);
  for( int i = 0; i &lt; width-1; ++i )
  {
    point( i, height/2 - (height*0.49) * wave.getWaveform().value( (float)i / width ) );
  }
}

void mouseMoved()
{
  // usually when setting the amplitude and frequency of an Oscil
  // you will want to patch something to the amplitude and frequency inputs
  // but this is a quick and easy way to turn the screen into
  // an x-y control for them.
  
  float amp = map( mouseY, 0, height, 1, 0 );
  wave.setAmplitude( amp );
  
  float freq = map( mouseX, 0, width, 110, 880 );
  wave.setFrequency( freq );
}

void keyPressed()
{ 
  switch( key )
  {
    case '1': 
      wave.setWaveform( Waves.SINE );
      break;
     
    case '2':
      wave.setWaveform( Waves.TRIANGLE );
      break;
     
    case '3':
      wave.setWaveform( Waves.SAW );
      break;
    
    case '4':
      wave.setWaveform( Waves.SQUARE );
      break;
      
    case '5':
      wave.setWaveform( Waves.QUARTERPULSE );
      break;
     
    default: break; 
  }
}
</pre>
    	<p class="memberSectionHeader">Usage</p>
    	Web & Application
    </td>
  </tr>
</table>
</center>
</body>
</html>